package com.we823.cms.repository.service.cms;

import java.util.List;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import com.we823.cms.common.web.pageable.Sort;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.jca.cci.core.InteractionCallback;
import org.springframework.stereotype.Service;

import com.we823.cms.model.cms.NewsChannel;
import com.we823.cms.model.cms.News;
import com.we823.cms.repository.dao.cms.NewsChannelMapper;
import com.we823.cms.repository.dao.cms.NewsMapper;
import com.we823.cms.repository.service.AbstractBaseService;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;

@Service("newsService")
@Scope("prototype")
public class NewsService extends AbstractBaseService<News, Integer> {

	private NewsMapper newsMapper;

	private @Resource NewsChannelMapper newsChannelMapper;
	
	@Autowired
	public NewsService(NewsMapper newsMapper) {
		super(newsMapper);
		this.newsMapper = newsMapper;
	}

	public List<News> findByChannel(Integer channelId, Sort sort) {
		setSortInfo(sort);
		return this.findByChannel(channelId);
	}

	public PageInfo<News> findByNewsChannel(Integer channelId, PageRequest pageRequest) {
		setPageInfo(pageRequest);
		return new PageInfo<>(this.findByChannel(channelId));
	}

	public List<News> findByChannel(Integer channelId){
		Example example = new Example(News.class);
		Example.Criteria criteria = example.createCriteria();
		criteria.andEqualTo("newsChannelId", channelId);
		return newsMapper.selectByExample(example);
	}

}
